package com.oa.ylms.apps.dao.archives.impl;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.oa.ylms.apps.constants.IDEDStates;
import com.oa.ylms.apps.dao.archives.IMajorInfoDao;
import com.oa.ylms.apps.entity.archives.MajorInfoValue;

public class MajorInfoDaoImpl extends HibernateDaoSupport implements
		IMajorInfoDao {

	@Override
	public int addMajorInfo(MajorInfoValue majorInfo) throws Exception {
		if(majorInfo != null){
			this.getHibernateTemplate().save(majorInfo);
			return majorInfo.getMajorId();
		}
		return 0;
	}

	@Override
	public boolean editMajorInfo(MajorInfoValue majorInfo) throws Exception {
		if(majorInfo != null){
			try{
				this.getHibernateTemplate().update(majorInfo);
			}catch(Exception e){
				return false;
			}
			return true;
		}
		return false;
	}

	@Override
	public MajorInfoValue queryByMajorId(MajorInfoValue majorInfo)
			throws Exception {
		if(majorInfo != null){
			return (MajorInfoValue) this.getHibernateTemplate().get(MajorInfoValue.class, majorInfo.getMajorId());
		}
		return null;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<MajorInfoValue> queryALLMajorInfo() throws Exception {
		String hql = "FROM MajorInfoValue miv WHERE miv.states = ?";
		return this.getHibernateTemplate().find(hql,IDEDStates.ENABLE);
	}
	
}
